package com.ma.chapter8.jdkpool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @ClassName TestExecution
 * @Author: mayongqiang
 * @DATE 2022/3/22 20:53
 * @Description: 异常处理
 */
@Slf4j(topic = "m.TestExecution")
public class TestExecution {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(1);
        //1、try catch 主动处理
        //pool.submit(() -> {
        //    log.debug("task1");
        //    try {
        //        int i = 1 / 0;
        //    } catch (Exception e) {
        //        e.printStackTrace();
        //    }
        //});
        // future 可以正确执行过程中的异常
        Future<Boolean> f = pool.submit(() -> {
            log.debug("task1");
            int i = 1 / 0;
            return true;
        });
        log.debug("f{}", f.get());


    }
}
